home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Text⁄Files
/
Writeswell Jr. 1.0.2 Master
/
Writeswell Jr. Source
/
PageSetup.c
< prev
next >
Wrap
Text File
|
1992-10-24
|
3KB
|
154 lines
/* PageSetup.c
* Do the page setup dialog in Writeswell Jr.
*
* ©1992 Working Software, Inc.
* This source code is copyrighted. Permission is granted to use the Word Services
* portion of the Writeswell Jr. source code in your own programs, but you
* may not distribute the Writeswell Jr. word-processor code as a
* commercial product. If you modify the code, please do not call it
* Writeswell Jr. (or Writeswell.) This will ensure that people understand the
* program and don’t have to deal with a number of different versions with
* who-knows-what going on in the code.
*
* Writeswell Jr. and Writeswell are trademarks of Working Software, Inc.
*
* 24 Oct 92 Mike Crawford
*/
#include <AppleEvents.h>
#include <Printing.h>
#include "TestBed.h"
#include "TBConstants.h"
#include "Gripe.h"
#include "Prefs.h"
#include "TBGlobals.h"
#include "PageSetup.h"
void DoPageSetup( void )
{
THPrint thePrRecHdl;
OSErr printErr;
Boolean saveSetup;
thePrRecHdl = GetPrintRecord();
if ( !thePrRecHdl ){
Gripe( "\pCannot get print record" );
return;
}
saveSetup = false;
PrOpen();
printErr = PrError();
if ( printErr == noErr ){
PrValidate( thePrRecHdl );
printErr = PrError();
if ( printErr == noErr ){
saveSetup = PrStlDialog( thePrRecHdl );
printErr = PrError();
}
}else{
Gripe( "\pCould not open the printer driver" );
}
PrClose();
if ( PrError() || printErr || !saveSetup ){
ReleaseResource( thePrRecHdl );
thePrRecHdl = NULL;
return;
}
ChangedResource( thePrRecHdl );
WriteResource( thePrRecHdl );
UpdateResFile( gPrefFileRefNum );
return;
}
THPrint GetPrintRecord( void )
{
THPrint thePrRecHdl;
short curFile;
long prRecSize;
OSErr err;
/* DO NOT Call this function while the printer driver is open */
curFile = CurResFile();
UseResFile( gPrefFileRefNum );
thePrRecHdl = (THPrint)Get1Resource( 'PStl', rPrintRecID );
UseResFile( curFile );
if ( thePrRecHdl ){
/* Validate the the handle is a good one */
prRecSize = GetHandleSize( thePrRecHdl );
if ( prRecSize != sizeof( TPrint ) ){
RmveResource( thePrRecHdl );
return (THPrint)NULL;
}
return thePrRecHdl;
}
/* At this point, no print record was found, so we create a new one */
thePrRecHdl = (THPrint)NewHandleClear( sizeof( TPrint ) );
if ( !thePrRecHdl )
return (THPrint)NULL;
/* Set the default values into the print record */
PrOpen();
if ( PrError() == noErr ){
PrintDefault( thePrRecHdl );
if ( PrError() != noErr ){
DisposHandle( thePrRecHdl );
thePrRecHdl = (THPrint)NULL;
}
}else{
DisposHandle( thePrRecHdl );
thePrRecHdl = (THPrint)NULL;
}
PrClose();
if ( thePrRecHdl == (THPrint)NULL )
return (THPrint)NULL;
/* At this point, we have a good print record. Save it into the
* preferences file
*/
UseResFile( gPrefFileRefNum );
AddResource( thePrRecHdl, 'PStl', rPrintRecID, "\pPage Setup" );
err = ResError();
UseResFile( curFile );
if ( err ){
DisposHandle( thePrRecHdl );
return (THPrint)NULL;
}
WriteResource( thePrRecHdl );
UpdateResFile( gPrefFileRefNum );
return thePrRecHdl;
}